unit U_fm_versao_cliente;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ImgList, Vcl.ToolWin,
  Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Buttons, Vcl.Grids, Vcl.DBGrids, Vcl.DBCtrls,
  Vcl.Mask;

type
  Tfm_versao_cliente = class(TForm)
    pnl1: TPanel;
    pnl2: TPanel;
    tlb1: TToolBar;
    btnadicionar: TToolButton;
    btngravar: TToolButton;
    btneditar: TToolButton;
    btncancelar: TToolButton;
    btnimprimir: TToolButton;
    btnprimeiro: TToolButton;
    btnanterior: TToolButton;
    btnproximo: TToolButton;
    btnultimo: TToolButton;
    btnexcluir: TToolButton;
    btnsair: TToolButton;
    il1: TImageList;
    tv1: TTreeView;
    btn1: TBitBtn;
    pnl3: TPanel;
    lbl5: TLabel;
    dbgrd1: TDBGrid;
    dbmmoHISTORICO: TDBMemo;
    btn2: TBitBtn;
    btn3: TBitBtn;
    grp1: TGroupBox;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl4: TLabel;
    lbl21: TLabel;
    lbl3: TLabel;
    lbl6: TLabel;
    lbl7: TLabel;
    btn12: TSpeedButton;
    dbedtDATANOW: TDBEdit;
    dbedt_versao: TDBEdit;
    dbedtVERSAO1: TDBEdit;
    dbedtDATANOW1: TDBEdit;
    dbedt_projeto: TDBEdit;
    edt1: TEdit;
    dbedtID: TDBEdit;
    procedure btn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btn12Click(Sender: TObject);
    procedure btnadicionarClick(Sender: TObject);
    procedure btngravarClick(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btnsairClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fm_versao_cliente: Tfm_versao_cliente;

implementation

{$R *.dfm}

uses U_dm_principal, U_fm_loc_proj;

procedure Tfm_versao_cliente.btn12Click(Sender: TObject);
begin
fm_loc_proj:=Tfm_loc_proj.Create(Application);
    fm_loc_proj.ShowModal;
 if fm_loc_proj.ModalResult=mrok then
 begin
   dbedt_projeto.Text:=dm_principal.cds_projetosDESCRICAO.Text;
 end;
end;

procedure Tfm_versao_cliente.btn1Click(Sender: TObject);

Var
  ItemUltiimoCurso, ItemUltimaUnidade, ItemUltimaTurma: TTreeNode;
  xUnidadeAnt, xCursoAnt, xTurmaAnt: String;
begin
  while not dm_principal.cds_versao.Eof do
  begin
    if xUnidadeAnt <> dm_principal.cds_versao.FieldByName('VERSAO').AsString then
    begin
      ItemUltimaUnidade := tv1.Items.AddChild(Nil,dm_principal.cds_versao.FieldByName('VERSAO').AsString);
    end;
    if xCursoAnt <>dm_principal.cds_versao.FieldByName('PROJETO').AsString then
    begin
      ItemUltiimoCurso := tv1.Items.AddChild(ItemUltimaUnidade, dm_principal.cds_versao.FieldByName('PROJETO').AsString);
    end;
    if xTurmaAnt <> dm_principal.cds_ver_cli.FieldByName('CLIENTE').AsString then
    begin
      ItemUltimaTurma := tv1.Items.AddChild(ItemUltiimoCurso,dm_principal.cds_ver_cli.FieldByName('CLIENTE').AsString);
    end;
    xUnidadeAnt := dm_principal.cds_versao.FieldByName('VERSAO').AsString;
    xCursoAnt := dm_principal.cds_versao.FieldByName('PROJETO').AsString;
    xTurmaAnt := dm_principal.cds_ver_cli.FieldByName('CLIENTE').AsString;
    dm_principal.cds_versao.Next;
  end;
end;


procedure Tfm_versao_cliente.btn2Click(Sender: TObject);
begin
dm_principal.cds_ver_cli.Insert;
dm_principal.sq_generators.Close;
dm_principal.sq_generators.SQL.Text:='select gen_id(GEN_VERSAO_CLIENTE_ID,1)as id from Rdb$database';
dm_principal.sq_generators.Open;
dm_principal.cds_ver_cliID.Value:=dm_principal.cds_versaoID.Value;
dm_principal.cds_ver_cliID.Value:=dm_principal.sq_generators.FieldByName('id').AsInteger;
dm_principal.cds_ver_cliCLIENTE.AsString:=dm_principal.cds_ver_cliCLIENTE.AsString+Edt1.Text;
dm_principal.cds_ver_cli.ApplyUpdates(0);
Edt1.Text:='';
Edt1.SetFocus;
end;

procedure Tfm_versao_cliente.btnadicionarClick(Sender: TObject);
begin
  dm_principal.cds_versao.Insert;
  dm_principal.sq_generators.Close;
  dm_principal.sq_generators.SQL.Text:='select gen_id(GEN_VERSAO_ID,1)as id from Rdb$database';
  dm_principal.sq_generators.Open;
  dm_principal.cds_versaoID.Value:=dm_principal.sq_generators.FieldByName('id').AsInteger;
  dm_principal.cds_VERSAODATA.Value:=Now;
end;

procedure Tfm_versao_cliente.btngravarClick(Sender: TObject);
begin
dm_principal.cds_versao.Post;
dm_principal.cds_versao.ApplyUpdates(0);

end;

procedure Tfm_versao_cliente.btnsairClick(Sender: TObject);
begin
Close;
end;

procedure Tfm_versao_cliente.FormCreate(Sender: TObject);
begin
dm_principal.cds_versao.Open;
dm_principal.cds_ver_cli.Open;
end;

procedure Tfm_versao_cliente.FormShow(Sender: TObject);
begin
dm_principal.cds_versao.Open;
dm_principal.cds_ver_cli.Open;
dm_principal.cds_ver_cli.MasterSource:= dm_principal.ds_versao;
end;

end.
